import Taro from '@tarojs/taro'
import app from '../../../../main.js'
let myJs = {
    getData: function() {
        this.state = {
            topicss: {
                items: []
            },
            articless: {
                offset: 0,
                length: 25,
                items: [{
                    id: '',
                    title: '',
                    image: '',
                    url: '',
                }]
            },
            dongtaiss: [],
            video: [],
            tbar_current: 1
        };
        return this.state;
    },
    getTopics() {
        var me = this;
        app.get('web/dynamic_topic/topicList', {offset: 0, length: 3}, function(res) {
            var topicss = me.state.topicss;
            topicss.items = res.data.result.list;
            me.setState({
                topicss: topicss
            });
        });
    },
    getDongtaiss() {
        var me = this;
        let list = [];
        app.get('web/dynamic_topic/dynamicList', {offset: this.offset, length: this.length}, function(res) {
            list  = me.state.dongtaiss.concat(res.data.result.list)
            me.setState({
                total: res.data.result.total,
                dongtaiss: list
            });
        });
    },
    
    navigateTo(url) {
        app.navigateTo(url);
    },
    handleChange(name, v) {
        var names = name.split('.');
        var n = names[0];
        var temp = this.state;
        for(var i = 0; i < names.length - 1; i++) {
            temp = temp[names[i]];
        }
        temp[names[i]] = v;
        this.setState({n: temp[names[i]]});
    },
    handleTextareaChange(name, e) {
        var names = name.split('.');
        var n = names[0];
        var temp = this.state;
        for(var i = 0; i < names.length - 1; i++) {
            temp = temp[names[i]];
        }
        temp[names[i]] = e.target.value;
        this.setState({n: temp[names[i]]});
    },
    redirectTo(url) {
        app.redirectTo(url);
    },

    componentDidMount () {

    },
    //进入页面执行
    componentDidShow () {
        this.init()
        this.getDongtaiss();
        this.getTopics();
    },
    componentWillUnmount () {
        console.log("页面站",Taro.getCurrentPages())
    },
    componentWillMount(){
        this.init()
    },
    componentDidHide () {

    }
}
export default myJs;
